﻿var obj1 = document.getElementById(Evolution_Pawp_ClientID);
if (obj1 != null)
    Evolution_Pawp_ChangeAction(obj1);

if (typeof (Evolution_Pawp_AssertionClientIDs) != "undefined") {
    for (i = 0; i < Evolution_Pawp_AssertionClientIDs.length; i++) {
        var sub1 = document.getElementById(Evolution_Pawp_AssertionClientIDs[i]);
        if (sub1 != null)
            Evolution_Pawp_ChangeAssertionSubject(sub1.selectedIndex, i)
    }
}

if (typeof(CurrentUser_OperatorIDs) != "undefined") {
    for (i = 0; i < CurrentUser_OperatorIDs.length; i++) {
        var dd = document.getElementById(CurrentUser_OperatorIDs[i++]);
        if (dd != null)
            Evolution_Pawp_SetCurrentUserOperator(dd.selectedIndex, document.getElementById(CurrentUser_OperatorIDs[i]));
    }
}

function Evolution_Pawp_ChangeAssertionSubject(index, pos) {
    var j = 0;
    while (document.getElementById("AssertionContainer" + pos + "_" + j) != null) {
        var obj = document.getElementById("AssertionContainer" + pos + "_" + j);
        obj.style.display = j++ == index ? "block" : "none";
    }
}

function Evolution_Pawp_ChangeAction(dropDown) {
    var index = dropDown.selectedIndex;
    for (i = 0; i < Evolution_Pawp_ActionContainersID.length; i++) {
        var obj = document.getElementById(Evolution_Pawp_ActionContainersID[i]);
        obj.style.display = i == index ? "block" : "none";
    }
}

function Evolution_Pawp_SetCurrentUserOperator(value, peoplePickerObject) {
    peoplePickerObject.style.display = value > 1 ? "none" : "block";    
}

function MsoFrameworkToolpartPreview(url,errorMessage,validTypes)
{
	url=url.replace(/(^\s*)|(\s*$)/g,"");	
	if (url.match(/^\s*(https?:\/\/)?\s*$/i)) return;	
	if ((MsoFrameworkToolpartCheckPath(url,validTypes) & validTypes) !=0 )
	{
		window.open(url);
	}
	else
	{
		alert(errorMessage);
	}
}
function MsoFrameworkToolpartCheckPath(url,validTypes)
{
	var testMask=0;
	if (validTypes & 1 || validTypes & 2)
	{
		testMask+=3;	
	}
	if (validTypes & 4 || validTypes & 8)
	{
		testMask+=4;	
	}
	var patterns=[/^(file:\/\/(\\\\|\/\/)?|\\\\)([^\\\/]+[\\\/]?)*$/i, /^(file:\/\/)?[a-zA-Z]:([\\\/][^\\\/]+)*[\\\/]?$/, /^(https?:\/\/|[\\\/])?([^\\\/]+[\\\/]?)*$/i];
	var lastDelimeter;
	var parsedUrl=null;
	for (i=0; i<patterns.length; i++)
	{
		if (testMask & (1 << i))
		{
			parsedUrl=url.match(patterns[i]);
			if (parsedUrl !=null)	
			{
				if (i==0 || i==1)
				{
					lastDelimeter=url.lastIndexOf('\\');
					if (lastDelimeter==-1) lastDelimeter=url.lastIndexOf('/');
					if (lastDelimeter==url.length-1)
					{
						return 2;	
					}
					else
					{
						return 3;	
					}
				}
				else	
				{
					return 12;	
				}
			}
		}
	}
	return 0;
}
